package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-06-16 16:39
 */
public class 题库_0121_买卖股票的最佳时机 {

  static
  class Solution {
    public int maxProfit(int[] prices) {
      if (prices == null || prices.length <= 1) {
        return 0;
      }
      int answer = 0;
      int low = Integer.MAX_VALUE;
      for (int i = 0; i < prices.length; ++i) {
        low = Math.min(low, prices[i]);
        answer = Math.max(answer, prices[i] - low);
      }
      return answer;
    }
  }

}
